package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageBean;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐相关接口")
@Slf4j
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 套餐分页查询
     *
     * @param dto 套餐dto
     * @return R
     */
    @GetMapping("/page")
    public Result<PageBean> pageList(SetmealPageQueryDTO dto) {
        PageBean pageBean = setmealService.pageList(dto);
        return Result.success(pageBean);
    }

    /**
     * 新增套餐
     *
     * @param setmealDTO dto
     * @return R
     */
    @PostMapping
    public Result add(@RequestBody SetmealDTO setmealDTO) {
        setmealService.add(setmealDTO);
        return Result.success();
    }

    /**
     * 根据id查询套餐
     *
     * @param id 套餐id
     * @return R
     */
    @GetMapping("/{id}")
    public Result<SetmealVO> selectById(@PathVariable Long id) {
        SetmealVO setmealVO = setmealService.selectById(id);
        return Result.success(setmealVO);
    }

    /**
     * 修改套餐
     *
     * @param setmealDTO 套餐dto
     * @return R
     */
    @PutMapping
    public Result<String> update(@RequestBody SetmealDTO setmealDTO) {
        log.info("修改套餐信息:{}", setmealDTO);
        setmealService.updateWithDish(setmealDTO);
        return Result.success();
    }

    /**
     * 套餐起售、停售
     *
     * @param status 套餐状态
     * @param id     套餐id
     * @return R
     */
    @PostMapping("/status/{status}")
    public Result<String> updateStatus(@PathVariable Integer status, Long id) {
        setmealService.updateStatus(status, id);
        return Result.success();
    }

    /**
     * 批量删除套餐
     *
     * @param ids 套餐id集合
     * @return R
     */
    @DeleteMapping
    public Result<String> deleteByIds(@RequestParam  List<Long> ids) {
        setmealService.deleteByIds(ids);
        return Result.success();
    }
}